package cst.a806yf.zyfypt_806yf.Fragment;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cst.a806yf.zyfypt_806yf.Adapter.TcaseAdapter;
import cst.a806yf.zyfypt_806yf.Linstener.AmicoolListener;
import cst.a806yf.zyfypt_806yf.Bean.TcaseBean;
import cst.a806yf.zyfypt_806yf.R;
import cst.a806yf.zyfypt_806yf.Model.ResModel;


/**
 * A simple {@link Fragment} subclass.
 */
public class TcaseFragment extends Fragment {
    private RecyclerView recyclerView;
    private TcaseAdapter adapter;
    private List<TcaseBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private AmicoolListener<List<TcaseBean>> listener;
    private ResModel model;
    private SharedPreferences sp;




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.tcasefragment, container, false);
        recyclerView=(RecyclerView)view.findViewById(R.id.anli);
        adapter =new TcaseAdapter(getActivity());
        list=new ArrayList<TcaseBean>();
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        listener=new AmicoolListener<List<TcaseBean>>() {
            @Override
            public void onResponse(List<TcaseBean> l) {
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        sp = getActivity().getSharedPreferences("ME", Context.MODE_APPEND);
        model = new ResModel("gson",sp.getString("session_id",""));
        model.getList("tcase",1,listener);
        return view;
    }

}
